package SqlJavaBean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class TeacherW {
	private Connection con;
	public String res;
	
	public TeacherW(Connection c){
		con = c;
		init();
	}
	
	private void init(){
		try{
			Statement sta = con.createStatement();
			sta.execute("use websql");
		}
		catch(Exception e){
			
		}
	}
	
	public boolean setPartGrade(String user,String data){
		String[] re = data.split("\u0001");
		try{
			String sql = "update Practise set whenLong=?,grade=?,ranks=? where practiseID=? and user='"+user+"'";
			PreparedStatement update = con.prepareStatement(sql);
			for(String s:re){
				String[] xxx = s.split("\u0002");
				update.setString(1, xxx[1]);
				update.setString(2, xxx[2]);
				update.setString(3, xxx[3]);
				update.setString(4, xxx[0]);
				update.executeUpdate();
			}
		}
		catch(Exception e){
			res = e.getMessage();
			return false;
		}
		return true;
	}
	public boolean setExamGrade(String user,String data){
		String[] re = data.split("\u0001");
		try{
			String sql = "update Subject set grade=? where subjectID=? and user='"+user+"'";
			PreparedStatement update = con.prepareStatement(sql);
			for(String s:re){
				String[] xxx = s.split("\u0002");
				update.setInt(1, Integer.valueOf(xxx[1]));
				update.setString(2, xxx[0]);
				update.executeUpdate();
			}
		}
		catch(Exception e){
			res = e.getMessage();
			return false;
		}
		return true;
	}
	
	public static void main(String[] s){
		String data = "2172338465";
		DBBean db = new DBBean();
		TeacherW tr = new TeacherW(db.getConnection());
		tr.setExamGrade("test",data);
	}
}
